package com.base.service.workflow.service.impl;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.base.core.framework.sql.service.impl.SqlBaseServiceImplV1Ext;
import com.base.core.head.constants.CodeResVal;
import com.base.service.workflow.bo.ProcessStatusEnum;
import com.base.service.workflow.dao.ProcessDao;
import com.base.service.workflow.entity.ProcessDO;
import com.base.service.workflow.service.ProcessService;
import com.gitee.magic.framework.head.exception.BusinessException;
import com.gitee.magic.jdbc.persistence.source.jdbc.sqlplus.conditions.update.UpdateWrapper;

/**
 * @author start 
 */
@Service("processService")
public class ProcessServiceImpl extends SqlBaseServiceImplV1Ext<ProcessDO,Long> 
implements ProcessService {

	private ProcessDao processDao;
	
	public ProcessServiceImpl(@Qualifier("processDao")ProcessDao processDao) {
		super(processDao);
		this.processDao=processDao;
	}

	@Override
	public void setStatus(Long processId, ProcessStatusEnum status) {
		UpdateWrapper wrapper=new UpdateWrapper();
		wrapper
			.eq("id", processId)
			.eq("status", String.valueOf(ProcessStatusEnum.PENDING))
			.set("status", String.valueOf(status));
		if(processDao.executeUpdate(wrapper)!=1) {
			throw new BusinessException(CodeResVal.CODE_10005);
		}
	}

}
